import axios from 'axios';

// 登录请求方法
const loginreq = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: params,
    traditional: true,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) +
            '=' +
            encodeURIComponent(data[it]) +
            '&'
        }
        return ret
      }
    ]
  }).then(res => res.data);
};
// 通用公用方法
const req = (method, url, params) => {
  return axios({
    method: method,
    url: 'http://10.206.33.163:8080/recommend' + url,
    //url: 'http://localhost:8080/recommend' + url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      //token: localStorage.getItem('logintoken')
    },
    data: params,
    traditional: true,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) +
            '=' +
            encodeURIComponent(data[it]) +
            '&'
        }
        return ret
      }
    ]
  }).then(res => res.data);
};


// url: 'http://10.206.33.163:8080/recommend'+url,

const reqjson = (method, url, params) => {
  return axios({
    method: method,
    url: 'http://10.206.33.163:8080/recommend' + url,
    //url: 'http://localhost:8080/recommend' + url,
    // headers: {
      // 'Content-Type': 'application/json;charset=utf-8',
      //token: localStorage.getItem('logintoken')
    // },
    data: params,
    traditional: true,
  }).then(res => res.data);
};

export {
  loginreq,
  req,
  reqjson
}
